/***************************************************************************
 *   Copyright (C) 2007 by les pandas rouges   *
 *   pouet@pouet   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef SHAPERECDISPLAYMANAGER_H
#define SHAPERECDISPLAYMANAGER_H

#include <QObject>
#include <QPen>
#include <QBrush>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsItem>
#include <QList>
#include <QSlider>
#include "myintpoint.h"
#include "shaperecdisplayinterface.h"
#define POINTZ 5
#define PATHLINEZ 4
#define ADDITIONALZ 2
#define CONTEXTZ 3
#define SCREENZ 0

/**
	@author les pandas rouges <pouet@pouet>
*/
class ShapeRecDisplayManager:public QObject, public ShapeRecDisplayInterface
{
    Q_OBJECT

private:
    int scale;
    QGraphicsView view;
    QSlider slid;
    QGraphicsScene scene;
    //screen
    QGraphicsItem* screen;
    //base display
    quint16 nbPoints;
    QGraphicsEllipseItem** points;
    QGraphicsLineItem** pathLines;
    //additional display
    QList<QGraphicsItem*> additionalDisplay;
    //context display
    QList<QGraphicsItem*> contextDisplay;
    //highlighted point
    QGraphicsEllipseItem* hlPoint;

public:
    inline QGraphicsView* getView()
    {
        return &this->view;
    }

    inline QSlider* getSlider()
    {
        return &this->slid;
    }

    ShapeRecDisplayManager();

    virtual ~ShapeRecDisplayManager();

    void setActivePoint(int ind);
    void drawPath(MyIntPoint* points, quint16 nbPoints);

    void drawAdditionalCircle(const MyIntPoint& center, unsigned short radius, MyColors penColor = DARKRED, MyColors brushColor=RED);

    void drawAdditionalRectangle(const MyIntPoint& topLeft, unsigned short width, unsigned short height, MyColors penColor=DARKRED, MyColors brushColor=RED);

    void drawAdditionalLine(const MyIntPoint& p1, const MyIntPoint& p2, MyColors penColor=DARKRED);

    void drawContextCircle(const MyIntPoint& center, unsigned short radius, MyColors penColor=DARKGREEN, MyColors brushColor=GREEN);

    void drawContextRectangle(const MyIntPoint& topLeft, unsigned short width, unsigned short height, MyColors penColor=DARKGREEN, MyColors brushColor=GREEN);

    void drawContextLine(const MyIntPoint& p1, const MyIntPoint& p2, MyColors penColor=DARKGREEN);

     void eraseBase();

     void eraseAdditional();

     void eraseContext();

     void eraseAll();

private slots:
     void changeScale(int value);


signals:
     void redrawAll();

private:
    static QColor convColor(MyColors c);

    QGraphicsLineItem* drawLine(const MyIntPoint& p1, const MyIntPoint& p2, const QPen& pen = QPen(Qt::blue));

    QGraphicsEllipseItem* drawCircle(const MyIntPoint& p, qreal radius = 0.5, const QPen& pen = QPen(Qt::black), const QBrush& brush = QBrush(Qt::black));

    QGraphicsRectItem* drawRectangle(const MyIntPoint& topLeft, quint16 width, quint16 height, const QPen& pen = QPen(Qt::black), const QBrush& brush = QBrush(Qt::black));

};

#endif
